package com.linkhub.oms.admin.modules.logistic.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.linkhub.oms.admin.modules.logistic.domain.param.*;
import com.linkhub.oms.admin.modules.logistic.domain.vo.ChannelPriorityVO;
import com.linkhub.oms.admin.modules.logistic.domain.vo.LogisticUrlDetailVO;
import com.linkhub.oms.admin.modules.logistic.domain.vo.LogisticVO;
import com.linkhub.oms.admin.modules.logistic.service.ChannelPriorityBizService;
import com.linkhub.oms.admin.modules.logistic.service.LogisticBizService;
import com.linkhub.oms.common.constant.RoleConstant;
import com.linkhub.oms.common.response.DataResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author Jaycle
 * @version 1.0.0
 * @Description LogisticController.java
 * @createTime 2024/04/29 22:04
 */

@Slf4j
@RestController
@Api(tags = {"物流管理模块"})
@RequestMapping("/logistic")
@SaCheckLogin
public class LogisticController {
    @Resource
    private LogisticBizService logisticBizService;

    @Resource
    private ChannelPriorityBizService channelPriorityBizService;

    @GetMapping("/list")
    @ApiOperation(value = "查询物流渠道列表接口")
    @SaCheckRole(value = {RoleConstant.CUSTOMER, RoleConstant.EMPLOYEE}, mode = SaMode.OR)
    public DataResponse<List<LogisticVO>> listLogistics( @Validated LogisticQueryParam logisticQueryParam ) {
        return DataResponse.success(logisticBizService.queryLogistics(logisticQueryParam));
    }

    @PutMapping("/edit_status")
    @ApiOperation(value = "更改物流渠道状态接口")
    @SaCheckRole(value = {RoleConstant.EMPLOYEE})
    public DataResponse<Void> editLogisticsStatus( @Validated @RequestBody LogisticEditStatusParam logisticEditStatusParam ) {
        logisticBizService.editLogisticsStatus(logisticEditStatusParam);
        return DataResponse.success();
    }

    @GetMapping("/query_channel_priority")
    @ApiOperation(value = "查询物流渠道优先级接口")
    @SaCheckRole(value = {RoleConstant.CUSTOMER})
    public DataResponse<List<ChannelPriorityVO>> queryChannelPriority( @Validated LogisticPriorityQueryParam logisticPriorityQueryParam ) {
        return DataResponse.success(channelPriorityBizService.queryChannelPriority(logisticPriorityQueryParam));
    }

    @PostMapping("/edit_channel_priority")
    @ApiOperation(value = "设置物流渠道优先级接口")
    @SaCheckRole(value = {RoleConstant.CUSTOMER})
    public DataResponse<Void> editChannelPriority( @Valid @RequestBody LogisticPriorityEditParam logisticPriorityEditParam ) {
        channelPriorityBizService.setChannelPriority(logisticPriorityEditParam);
        return DataResponse.success();
    }

    @PostMapping("/set_logistic_url")
    @ApiOperation(value = "物流查询网址设置接口")
    @SaCheckRole(value = {RoleConstant.CUSTOMER})
    public DataResponse<Void> setLogisticUrl( @Valid @RequestBody LogisticUrlEditParam logisticUrlEditParam ) {
        logisticBizService.setLogisticUrl(logisticUrlEditParam);
        return DataResponse.success();
    }

    @GetMapping("/logistic_url_detail")
    @ApiOperation(value = "物流查询网址详情查询接口")
    @SaCheckRole(value = {RoleConstant.CUSTOMER})
    public DataResponse<LogisticUrlDetailVO> queryLogisticUrlDetail( @Valid LogisticUrlQueryParam logisticUrlQueryParam ) {
        return DataResponse.success(logisticBizService.queryLogisticUrlDetail(logisticUrlQueryParam));
    }

    @GetMapping("/logistics_tracking")
    @ApiOperation(value = "物流轨迹查询接口")
    @SaCheckRole(value = {RoleConstant.CUSTOMER, RoleConstant.EMPLOYEE}, mode = SaMode.OR)
    public DataResponse<String> queryLogisticsTracking( @Valid LogisticsTrackingQueryParam logisticsTrackingQueryParam ) {
        return DataResponse.success(logisticBizService.queryLogisticsTracking(logisticsTrackingQueryParam));
    }

}
